﻿/*
* 简历中心--我的面试--弹窗
* 2016-7-14
* */
//面试评价弹窗
function evaluateInterview(data){
    var companyName = data.name, wrapId = data.contentBoxId, popHtml = $('<div class="evaluate_popcon" id="' + wrapId + '">' +
        '<div class="evaluate_bottom">' +
        '<div class="evaluate_tips"><p>请至少选择1个标签或填写评语</p></div><div class="evaluate_title"><p>点评<span>' + companyName + '</span><i>- 最多可选8个标签</i></p></div>' +
        '<div class="evaluate_advantage">' +
        '<p class="mb20"><a href="javascript:void(0);">公司高大上</a><a href="javascript:void(0);">前台很漂亮</a><a href="javascript:void(0);">面试过程愉快</a>' +
        '<a href="javascript:void(0);">公司福利好</a><a href="javascript:void(0);" class="lastbq">公司气氛好</a></p>' +
        '<p><a href="javascript:void(0);">公司环境好</a><a href="javascript:void(0);">面试官很nice</a><a href="javascript:void(0);">交通很方便</a><a href="javascript:void(0);">颜值普遍很高</a></p>' +
        '</div>' +
        '<div class="evaluate_shortcom">' +
        '<p class="mb20"> <a href="javascript:void(0);">等的时间太久</a><a href="javascript:void(0);">性别歧视</a><a href="javascript:void(0);">面试官很难聊</a>' +
        '<a href="javascript:void(0);">收取押金</a><a href="javascript:void(0);" class="lastbq">交通不方便</a></p><p><a href="javascript:void(0);">环境有点乱</a></p>' +
        '</div>' +
        '<div><textarea class="text_input"></textarea><p class="number_count">您还可以输入<span>2000</span>个字</p></div>' +
        '<div class="submit_btn"><a href="javascript:void(0);">提交评价</a></div>' +
        '</div>' +
        '</div>');
    var tipDiv = popHtml.find('.evaluate_tips'), countSpan = popHtml.find('.number_count span'), layIndex,
    //优点评价
    good = popHtml.find('.evaluate_advantage p a').bind('click', function(){
        var t = $(this), goodA = good.filter('.check_advantage'), badA = bad.filter('.check_shortcom');
        if(t.hasClass('check_advantage')){
            t.removeClass('check_advantage');
            popHtml.find('.evaluate_title i').css('color', '#555555');
        }else if(goodA.length + badA.length < 8){
            t.addClass('check_advantage');
            tipDiv.hide();
        }else{
            popHtml.find('.evaluate_title i').css('color', '#f46254');
        }
    }),
    //缺点评价
    bad = popHtml.find('.evaluate_shortcom p a').bind('click', function(){
        var t = $(this), goodA = good.filter('.check_advantage'), badA = bad.filter('.check_shortcom');
        if(t.hasClass('check_shortcom')){
            t.removeClass('check_shortcom');
            popHtml.find('.evaluate_title i').css('color', '#555555');
        }else if(goodA.length + badA.length < 8){
            t.addClass('check_shortcom');
            tipDiv.hide();
        }else{
            popHtml.find('.evaluate_title i').css('color', '#f46254');
        }
    }),
    //手动填写的评价
    ownText = popHtml.find('.text_input').bind('keyup change', function(){
        var t = $(this), v = t.val(), l = 2000;
        if(v.length >= l){
            t.val(v.substr(0, l));
            countSpan.html(0);
        }else{
            countSpan.html(l - v.length);
        }
    });
    //提交评价
    popHtml.find('.submit_btn a').bind('click', function(){
        var goodA = good.filter('.check_advantage'), badA = bad.filter('.check_shortcom'), val = ownText.val(), t = $(this);
        if(goodA.length == 0 && badA.length == 0 && !val){
            tipDiv.show();
            return false;
        }
        var gAry = [], bAry = [];
        goodA.each(function(){
            gAry.push($(this).text());
        });
        badA.each(function(){
            bAry.push($(this).text());
        });
        if(typeof data.callSubmit == 'function'){
            data.callSubmit({contStr: val, badStr: bAry.join(','), goodStr: gAry.join(','), btnSubmit : t});
        }
    });
    $('body').append(popHtml);//必须先把div对应的jQuery对象添加到页面后才能在layer的弹窗中使用，所以在销毁layer弹窗时需要把该jQuery对象对应的div删掉
    layIndex = layer.open({
        type: 1,
        title: ['评价', 'font-size:18px;color:#555555;'],
        content: popHtml,
        area: '838px',
        end : function(){
            //由于必须先把div对应的jQuery对象添加到页面后才能在layer的弹窗中使用，所以在销毁layer弹窗时需要把该jQuery对象对应的div删掉
            $('#' + wrapId).remove();
        },
        cancel: function(){
            if( typeof data.callClose == 'function'){
                data.callClose();
            }
        }
    });
    return layIndex;
}
//面试评价信息显示弹窗
function evaluationInfo(data){
    var companyName = data.name, wrapId = data.contentBoxId, info = data.comment, comments = info.comments, gl = comments.good.length, bl = comments.bad.length,
        goodHtm = '', badHtm = '', content = comments.content, popHtml, flag = true, layIndex, t1 = 0, t2 = 0;
    //好的评价
    if(gl > 0){
        var gdStr = '';
        for(var i = 0; i < gl; i ++){
            if(comments.good[i]){
                t1 += 1;
                if(i == gl - 1){
                    gdStr += '<a href="javascript:void(0);" class="lastbq" style="cursor:default;">' + comments.good[i] + '</a>';
                }else{
                    gdStr += '<a href="javascript:void(0);" style="cursor:default;">' + comments.good[i] + '</a>';
                }
            }
        }
        if(gdStr){
            goodHtm = '<div class="evaluated_advantage"><p class="">' + gdStr + '</p></div>';
        }
    }
    //缺点评价
    if(bl > 0){
        var bdStr = '';
        for(var j = 0; j < bl; j ++){
            if(comments.bad[j]){
                t2 += 1;
                if(j == bl - 1){
                    bdStr += '<a href="javascript:void(0);" class="lastbq" style="cursor:default;">' + comments.bad[j] + '</a>';
                }else{
                    bdStr += '<a href="javascript:void(0);" style="cursor:default;">' + comments.bad[j] + '</a>';
                }
            }
        }
        if(bdStr){
            badHtm = '<div class="evaluated_shortcom"><p>' + bdStr + '</p></div>';
            flag = false;
        }
    }
    //手动填写的评价
    var maxH = 400 - Math.ceil(t1/5) * 60 - Math.ceil(t2/5) * 70;
    if(content){
        content = '<div class="view_sourtxt"><p>面试过程：</p><p class="evaluate_text" style="max-height:' + maxH + 'px;overflow-y:auto;">' + content + '</p></div>';
    }else{
        content = '';
    }
    popHtml = $('<div class="evaluated_popcon" id="' + wrapId + '"><div class="evaluate_bottom">' +
        '<div class="evaluate_title"><p>点评 <span>' + companyName + '</span></p></div>' + goodHtm + badHtm + content + '</div></div>');
    //没有'缺点评价'时需要把'优点评价'的下边框去掉
    if(flag){
        popHtml.find('.evaluated_advantage').css('border', 'none');
    }
    $('body').append(popHtml);//必须先把div对应的jQuery对象添加到页面后才能在layer的弹窗中使用，所以在销毁layer弹窗时需要把该jQuery对象对应的div删掉
    layIndex = layer.open({
        type: 1,
        title: ['评价', 'font-size:18px;color:#555555;'],
        content: popHtml,
        area: '838px',
        end : function(){
            //由于必须先把div对应的jQuery对象添加到页面后才能在layer的弹窗中使用，所以在销毁layer弹窗时需要把该jQuery对象对应的div删掉
            $('#' + wrapId).remove();
        }
    });
    return layIndex;
}
//拒绝面试原因弹窗
function refusalReasons(data){
    var wrapId = data.contentBoxId, popHtml = $('<div class="refreason_popcon" id="' + wrapId + '"><div class="refreason_mid"><div class="refreason_tips"><p>请至少选择1个原因或填写原因</p></div>' +
        '<div class="refrason_content"><div class="refreason_check"><div class="recheck_title"><p>请选择你拒绝的原因 - 可多选</p></div>' +
        '<div class="rechoice"><p class="mb20"><a href="javascript:void(0);">路程较远</a><a href="javascript:void(0);">薪水差距较大</a><a href="javascript:void(0);" class="lastbq">福利太少</a></p>' +
        '<p><a href="javascript:void(0);">行业不匹配</a><a href="javascript:void(0);">项目不吸引人</a></p></div></div>' +
        '<div class="refreason_other"><div class="refreason_othert"><p>其他</p></div><div class="refreason_otherm"><textarea placeholder="说说拒绝的原因..." class="refreason_txt"></textarea>' +
        '<p class="number_count">您还可以输入<span>100</span>个字</p></div></div><div class="refreason_otherbtn"><a href="javascript:void(0);" class="btnBlueBig noresease">不选原因，直接拒绝</a>' +
        '<a href="javascript:void(0);" class="btnBlueBig haveresease">提交评价</a></div></div></div></div>');
    var resTip = popHtml.find('.refreason_tips'), countSpan = popHtml.find('.number_count span'), layIndex,
    //拒绝原因
    reason = popHtml.find('.rechoice p a').bind('click', function(){
        var t = $(this);
        if(t.hasClass('check_advantage')){
            t.removeClass('check_advantage');
        }else{
            t.addClass('check_advantage');
            resTip.hide();
        }
    }),
    //其他拒绝的原因
    otherRes = popHtml.find('.refreason_txt').bind('keyup', function(){
        var t = $(this), v = t.val(), l = 100;
        if(v.length >= l){
            t.val(v.substr(0, l));
            countSpan.html(0);
        }else{
            countSpan.html(l - v.length);
        }
        v && resTip.hide();
    });
    //不选原因，直接拒绝
    popHtml.find('.noresease').bind('click', function(){
        var t = $(this);
        if(typeof data.callSubmit == 'function'){
            data.callSubmit({fillReason: '', reasonAry: [], reasonHave: 'no', btnSubmit : t});
        }
    });
    //提交评价
    popHtml.find('.haveresease').bind('click', function(){
        var resSelect = reason.filter('.check_advantage'), val = otherRes.val(), t = $(this);
        if(resSelect.length == 0 && !val){
            resTip.show();
            return false;
        }
        var resAry = [];
        resSelect.each(function(){
            resAry.push($(this).text());
        });
        if(typeof data.callSubmit == 'function'){
            data.callSubmit({fillReason: val, reasonAry: resAry, reasonHave: 'yes', btnSubmit : t});
        }
    });
    $('body').append(popHtml);//必须先把div对应的jQuery对象添加到页面后才能在layer的弹窗中使用，所以在销毁layer弹窗时需要把该jQuery对象对应的div删掉
    layIndex = layer.open({
        type: 1,
        title: ['拒绝原因', 'font-size:18px;'],
        content: popHtml,
        area: '510px',
        end : function(){
            //由于必须先把div对应的jQuery对象添加到页面后才能在layer的弹窗中使用，所以在销毁layer弹窗时需要把该jQuery对象对应的div删掉
            $('#' + wrapId).remove();
            if(typeof data.callClose == 'function'){
                data.callClose();
            }
        }
    });
    return layIndex;
}
//接受面试邀请弹窗(非到面)
function acceptConfirmTips(data){
    var wrapId = data.contentBoxId, tip = data.tip || '你已接受企业的职位邀请，请保持手机畅通，企业会尽快与你联系。', popHtml = $('<div class="acceptin_bottom" id="' + wrapId + '"><p class="accept_tips">' + tip + '</p>'+
        '<p><a href="javascript:void(0);" class="btnBlueBig ml173">知道了</a></p></div>'), layIndex, t = $(this);
    //知道了
    popHtml.find('.btnBlueBig').bind('click', function(){
        if(typeof data.callOk == 'function'){
            data.callOk({btnSubmit : t});
            //layer.close(layIndex);
        }
    });
    $('body').append(popHtml);//必须先把div对应的jQuery对象添加到页面后才能在layer的弹窗中使用，所以在销毁layer弹窗时需要把该jQuery对象对应的div删掉
    layIndex = layer.open({
        type: 1,
        title: ['提示', 'font-size:18px;'],
        content: popHtml,
        area: '510px',
        end : function(){
            //由于必须先把div对应的jQuery对象添加到页面后才能在layer的弹窗中使用，所以在销毁layer弹窗时需要把该jQuery对象对应的div删掉
            $('#' + wrapId).remove();
            if(typeof data.callClose == 'function'){
                data.callClose();
            }
        }
    });
    return layIndex;
}
//当天不可修改面试时间弹窗
function timeNoChangeTips(){
    var wrapId = data.contentBoxId, tip = data.tip || '面试当天不可修改时间哦，如面试时间有冲突请尽快联系HR。', popHtml = $('<div class="nomodify_bottom" id="' + wrapId + '"><p class="accept_tips">' + tip + '</p>'+
        '<p><a href="javascript:void(0);" class="btnBlueBig ml173">知道了</a></p></div>'), layIndex;
    //知道了
    popHtml.find('.btnBlueBig').bind('click', function(){
        var t = $(this);
        if(typeof data.callOk == 'function'){
            data.callOk({btnSubmit : t});
            //layer.close(layIndex);
        }
    });
    $('body').append(popHtml);//必须先把div对应的jQuery对象添加到页面后才能在layer的弹窗中使用，所以在销毁layer弹窗时需要把该jQuery对象对应的div删掉
    layIndex = layer.open({
        type: 1,
        title: ['提示', 'font-size:18px;'],
        content: popHtml,
        area: '510px',
        end : function(){
            //由于必须先把div对应的jQuery对象添加到页面后才能在layer的弹窗中使用，所以在销毁layer弹窗时需要把该jQuery对象对应的div删掉
            $('#' + wrapId).remove();
        }
    });
    return layIndex;
}